<?php
require_once('func_db.php');

class wwPageItem {
	var $blogtitle;
	var $bloghome;
	var $postlist;
	var $pagenum	=	1;
	var $ran			= 10;
	var $term			=	'all';

	function wwPageItem($page) {
		$this->blogtitle	=	db_options('blogname');
		$this->bloghome		=	db_options('home');
		if(!empty($page)){
			$this->pagenum		=	$page;
		}
		$this->postlist		=	$this->getPostList($this->term, $this->pagenum, $this->ran);
		return 0;
	}

	function getPostList($term, $pagenum, $range) {
		return db_postlist($term, $pagenum, $range);
	}

	function getPost($post_id) {
		return db_post($post_id);
	}
	
	function getCat($post_id) {
		$cats	=	db_cat($post_id);
		if(count($cats) == 1){
			$result	= $cats[0]->name;
		}
		else{
			foreach($cats as $key => $value) {
				$result	.=	$value->name.', ';
			}
			$result	=	preg_replace("/, $/i","",$result);
		}
		return $result;
	}

	function getAuthor($author){
		return db_author($author);
	}

	function showAD(){
//		$ww_option = db_options('WapWordPressAdminOptions');
		$ww_option		=	$this->getArrayFromOption();
//		print_r($ar);

		if($ww_option['ww_ad_on'] == 'on'){
			//copy from 'func_cls.php' function getADPath()
			$adpath	= dirname(__FILE__).'/../files/ad-wap-code.php';
			$adpath	= str_replace('\\', '/', $adpath);
//			echo $adpath;
			include $adpath;
		}
	}

	function getArrayFromOption() {
		$wwAdminOptions = array('ww_is_on' => '', 'ww_wap_path' => '/wap', 'ww_ad_on' => '');

		$str			= db_options('WapWordPressAdminOptions');
		$strlen		= strlen($str);
		$str			= substr($str, 5, $strlen-7);

		$opts			= explode(';', $str);
		for($i=0;$i<3;$i++){
			$opt_n			= explode(':', $opts[$i*2]);
			$opt_v			= explode(':', $opts[$i*2+1]);
			$opt_name	=	substr($opt_n[2], 1, strlen($opt_n[2])-2);
			$opt_val	=	substr($opt_v[2], 1, strlen($opt_v[2])-2);
			$wwAdminOptions[$opt_name]	= $opt_val;
		}
		return $wwAdminOptions;
	}

	function navi() {
		$post_num	=	db_var('post_num');
		$page_num	=	ceil($post_num / $this->ran);
		if($this->pagenum == 1){
			echo "<a href=\"./index.php?page=".($this->pagenum+1)."\">前一页</a>";
		}
		elseif($this->pagenum == $page_num){
			echo "<a href=\"./index.php?page=".($this->pagenum-1)."\">后一页</a>";
		}
		else
		{
			echo "<a href=\"./index.php?page=".($this->pagenum+1)."\">前一页</a>"." | "."<a href=\"./index.php?page=".($this->pagenum-1)."\">后一页</a>";
		}
	}


}


?>